﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Imaginecup.sprite;

namespace Imaginecup.util.particle
{
    public class TouchEffectGenerator
    {
        private static Vector2 m_EnablePos;
        private static Vector2 m_EnableSize;


        public TouchEffectGenerator() { }

        public static  void SetEnableData(Vector2 pos, Vector2 size)
        {
            m_EnablePos = pos;
            m_EnableSize = size;
        }
        
        public void GeneratorParticle()
        {
            CheckInput();
        }
       
        private void CheckInput()
        {

            IMouseInputHandler input = MouseInputHandler.GetInputHandler();

            if (input.IsOneClick())
            {
#if !XBOX
                CreateParticle(new Vector2(input.MouseState.X, input.MouseState.Y));
#endif
#if XBOX
                CreateParticle(input.Position);
#endif
            }

        }

        private void CreateParticle( Vector2 position )
        {
            
            Vector2 v = new Vector2(0 , 1); // 초기값 오른쪽 방향으로 간다.
            for( int i = 0 ; i < 36 ; i++ )
            {
                Vector2 dir = Vector2.Transform(v, Matrix.CreateRotationZ( MathHelper.ToRadians(i * 10) ));

                Particle particle = new Particle(position, Color.Yellow, 0.2 +
                RandomUtil.rand.NextDouble(), new Vector2(10, 10), dir, 15 , ParticleType.TouchEffect);

                ParticleSprite particleSprite = new ParticleSprite();
                particleSprite.SetColorClass(particle);
                particleSprite.SetTextureName("Particle");

                particle.SetSprite(particleSprite);

                //1초에 3픽셀씩 dir방향으로 가는 지속시간 0.3초인 흰색 파티클 추가한다.
                ParticleMan.GetParticleMan().AddParticle(particle);

            }
        }
    }
}
